// house_pkg/pages/locate/index.ts
// 导入地图 SDK
import qqMap from "../../../utils/qqMap"
Page({
  goBuilding(ev) {
    wx.navigateTo({
      url: '/house_pkg/pages/building/index?point=' + ev.mark.point
    })
  },
  onLoad(){
    this.getLocation()
  },
  // 获取用户当前所在位置的经纬度
  async getLocation() {
    const { latitude, longitude } = await wx.getLocation()
    console.log(latitude, longitude);
    this.getPoint(latitude, longitude)
  },
  // 获取用户指定位置的经纬度
  async chooseLocation(){
    const {latitude, longitude} = await wx.chooseLocation()
    console.log(latitude, longitude);
    this.getPoint(latitude, longitude)
  },
  // 获取经纬度信息
  getPoint(latitude, longitude) {
    qqMap.reverseGeocoder({
      location:[latitude, longitude].join(','),
      success:(res) =>{
        console.log(res.result.address);
        this.setData({
          address: res.result.address
        })
      }
    })
    //根据维度搜索周边的小区信息
  qqMap.search({
    keyword: '小区',
    location: [latitude, longitude].join(','),
    page_size: 5,
    success: (res) =>{
      console.log(res)
      this.setData({
        points: res.data
      })
    }

  })
  },
  

})